package com.bw.dao;

import com.bw.pojo.comment.ItemProductPages;
import com.bw.pojo.comment.ProductReply;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface ProductReplyMapper extends Mapper<ProductReply> {

    @Select("select avg(product_score) from product_reply where sku_id = #{skuId}")
    public Double Satisfaction(@Param("skuId") String skuId);
    @Select("<script>" +
            "select * from product_reply where (sku_id in"+
            "<foreach collection='skuIds' item='item' open='(' separator=',' close=')'>" +
            "#{item} "+
            "</foreach>" +
            "or reply_content like #{replyContent}) " +
            "and product_type=#{productType} " +
            "and user_name=#{userName}"+
            "</script>")

    public List<ProductReply> findList (@Param("skuIds") Object skuIds, @Param("replyContent") Object replyContent, @Param("productType") Object productType, @Param("userName") Object userName);

    @Select("update product_reply set follow_content=NULL,follow_image=NULL " +
            "where id=#{id}")
    public void deleteFollow(@Param("id") String id);

    @Select("SELECT sku_id from order_item where order_id in " +
            " (SELECT id from tb_order WHERE order_status=4)")
    public String skuid();

    @Select("SELECT spu_id from order_item where order_id in " +
            " (SELECT id from tb_order WHERE order_status=4)")
    public String spuid();

    @Select("SELECT id from tb_order WHERE order_status=4")
    public String orderid();

    @Select("select count(*) from product_reply WHERE sku_id= #{skuId} \n" +
            " and reply_image is not NULL;\n")
    public Integer getHasPictureCommentsCount(@Param("skuId") String skuId);


    @Select("select count(*) from product_reply WHERE sku_id= #{skuId};")
    public Integer getAllCommentsCount(@Param("skuId") String skuId);

    @Select("SELECT count(*) from product_reply WHERE sku_id= #{skuId}\n" +
            " and follow_content is not null;")
    public Integer getHasFollowCommentsCount(@Param("skuId") String skuId);

    @Select("SELECT count(*) from product_reply WHERE sku_id=#{skuId}\n" +
            " and product_score>3;")
    public Integer getGoodCommentsCount(@Param("skuId") String skuId);

    @Select("SELECT count(*) from product_reply WHERE sku_id=#{skuId}\n" +
            " and product_score=3;")
    public Integer getMiddleCommentsCount(@Param("skuId") String skuId);
    @Select("SELECT count(*) from product_reply WHERE sku_id=#{skuId}\n" +
            " and product_score<3;")
    public Integer getBadCommentsCount(@Param("skuId") String skuId);

    @Select("SELECT id FROM tb_order WHERE username=#{username} and buyer_rate=1")
    public List<ItemProductPages> getOrderId(@Param("username") String username);

}
